package com.liruan.rest.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import com.liruan.rest.po.UserInfoPO;

public interface UserInfoMapper
{
	@Results(id = "BaseMap", value = {@Result(column = "id", property = "id"), @Result(column = "phone", property = "phone"), @Result(column = "password", property = "password")})
	@Select("select id, phone, password from user_info where phone=#{phone} and password=#{password}")
	UserInfoPO selectUser(@Param("phone") String phone, @Param("password") String password);

	@Select("select if(count(1)=0, 0, 1) as exist from user_info where id=#{id}")
	Boolean existUser(@Param("id") Long id);

	@Select("select if(count(1)=0, 0, 1) as exist from user_info where phone=#{phone}")
	Boolean existUserByPhone(@Param("phone") String phone);

	@Options(useGeneratedKeys = true, keyProperty = "user.id")
	@Insert("insert into user_info (phone, password, create_time, update_time) values(#{user.phone},#{user.password},#{user.createTime}, #{user.updateTime})")
	void insertOneUser(@Param("user") UserInfoPO user);
}
